Skip to content

[Feature] Add LeRobot replay dataset adapter - #4611

Merged
bsprenger merged 5 commits into
pytorch:mainfrom
bsprenger:feat/lerobot-replay-dataset-adapter
Oct 27, 2026
Merged

bsprenger merged 5 commits into
pytorch:mainfrom
bsprenger:feat/lerobot-replay-dataset-adapter

Conversation

@bsprenger

Copy link
Copy Markdown
Collaborator

Description

This PR adds a LeRobot replay dataset adapter, which can be used to export a replay buffer's contents to the LeRobot format.

Motivation and Context

LeRobot is a widely used robotics dataset format. Conversion to/from LeRobot datasets will allow sharing of trajectories for offline learning, and for pre-seeding replay buffers with LeRobot-format data from the Hugging Face hub.

An upcoming PR will add examples and benchmarks.

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

What types of changes does your code introduce? Remove all that do not apply:

  • New feature (non-breaking change which adds core functionality)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

@bsprenger
bsprenger requested a review from theap06 October 23, 2026 13:02
@bsprenger bsprenger self-assigned this Oct 23, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4611

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit d257b67 with merge base c0ca870 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 23, 2026
@github-actions github-actions Bot added Documentation Improvements or additions to documentation Environments Adds or modifies an environment wrapper Data Data-related PR, will launch data-related jobs Feature New feature labels Oct 23, 2026

@theap06 theap06 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a bunch! I agree with the overall direction and tested out the logic and wrote to hf. left a couple small comments.

assert decoded.dtype == torch.uint8


@pytest.mark.skipif(not _has_lerobot_dataset, reason="requires torchrl[lerobot]")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a py3.12 stable-torch job to have the ci job run for this?

fps: int | None = None,
features: Mapping[str, dict[str, Any]] | None = None,
key_map: Mapping[str, NestedKey] | None = None,
episode_key: NestedKey = "episode",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now the episode_key and the step_key duplicate what key_map has. so if we use a keymap to rename we would get a KeyError. can we derive the keys from key_map and drop these args?

)
if isinstance(value, MetaData):
columns[name] = [value.data] * len(batch)
elif isinstance(value, torch.Tensor):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we permute chw frames to the feature layout on export? my concern here is that if we import a hub dataset, it gives us chw float images and the the hub schema is hwc.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I used a simple shape-based heuristic which should work in almost all cases, but I left a TODO to address this more thoroughly in a follow up.

previous_episode, previous_step = episode, step
native.save_episode(parallel_encoding=False)
native.finalize()
except BaseException:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this leave the root with a partial dataset that is marked as valid? can we use rmtree to delete the partial dataset and re-raise an error here in that scenario?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks for the callout

@theap06

theap06 commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

@bsprenger build-docs ci was triggered before i merged the fix in.

@github-actions github-actions Bot added the CI Has to do with CI setup (e.g. wheels & builds, tests...) label Oct 27, 2026
@bsprenger
bsprenger force-pushed the feat/lerobot-replay-dataset-adapter branch from 2da2b1c to 027d7e4 Compare October 27, 2026 00:52
@bsprenger
bsprenger merged commit 380dd55 into pytorch:main Oct 27, 2026
125 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Has to do with CI setup (e.g. wheels & builds, tests...) CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Data Data-related PR, will launch data-related jobs Documentation Improvements or additions to documentation Environments Adds or modifies an environment wrapper Feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants